// Copyright (C) 2012 by Johann Duscher <jonny.dee@gmx.net>
//
// This file is part of barcodeart-pp.
//
// barcodeart-pp is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// barcodeart-pp is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with barcodeart-pp. If not, see <http://www.gnu.org/licenses/>.

#pragma once

#include "barcodeart/IPluginContext.hpp"


namespace barcodeart
{

class IPlugin;

template <typename TPluginInterface, typename TPluginContextInterface>
class APlugin : public TPluginInterface
{
public:
    virtual ~APlugin() {}

    virtual void init(IPluginContext& ctx)
    {
        (void)static_cast<IPlugin* const>(this);

        m_pPluginContext = &dynamic_cast<TPluginContextInterface&>(ctx);

        initInternal();
    }

    virtual const char* getName() const = 0;
    virtual const char* getDesciption() const = 0;

protected:
    APlugin()
    {
    }

    virtual void initInternal() {}

    TPluginContextInterface& getPluginContext() const
    {
        return *m_pPluginContext;
    }

private:
    TPluginContextInterface* m_pPluginContext;
};

}
